import React from 'react'
import {Table,Button} from 'antd'
import styles from './Sendpolice.less'
import { Color } from 'chalk'
import { select } from 'react-cookies'
import {connect} from 'react-redux'
import * as actions from '../../request/action'

class Index extends React.Component{
    constructor(props){
        super(props)
        this.state={
            Policeofficers:'' ,//派警人员id
            id:''//告警id

        }
        
    }
    componentDidMount(){
        this.props.getalluser()
        this.setState({
            id:this.props.id ,
        })
    }
    onClick=()=>{
        let information={
            key:this.props.id ,
            basicDataId:this.state.Policeofficers[0].id,
            isDistribute:"distribute",
            camerId:this.props.camerId,
            currentpage:this.props.currentpage-1

        }
        this.props.close()

        this.props.Distribute(information)
        // this.props.getcamera()
    }
    render(){
     
        const rowSelection={
            type:'radio',
            onChange:(selectedRowKeys,selectedRows)=>{
     
                this.setState({
                    Policeofficers: selectedRows
                })
            }
        }
        const columns =[
            {
                title:'用户名',
                dataIndex:'name',
                className:styles.columns
            },
            {
                title:'所属机构',
                dataIndex:'institutionsName',
                className:styles.columns
            }
        ]
        return(
            <div className={styles.totall}>
                <Table className={styles.table} rowSelection={rowSelection} columns={columns} dataSource={this.props.Listofworkers.length==0?null:this.props.Listofworkers}
                                    onRow={(record,rowkey)=>{
                                        return{
                                            onClick:event =>{
                                             
                                                event.currentTarget.getElementsByClassName("ant-radio-wrapper")[0].click();
                                                             }
                                        }
                                    }}

                ></Table>
                <Button  disabled={this.state.Policeofficers==''?true:false} style={{marginLeft:'48%',color:'black'}} onClick={this.onClick}>派警</Button>
            </div>
        )
}
}
const mapStateToProps = (state) => ({
    Listofworkers: state.Mapcamera.Listofworkers,
    
})
const mapDispatchToProps = (dispatch) => ({
    getalluser() {
        dispatch(actions.getAlluserRequest())
    },
    Distribute(information) {
        dispatch(actions.Distribute(information))
    },
    getcamera(){
        dispatch(actions.getAllCamera())
    },
    Gethistoricalalarms(id){
        dispatch(actions.Gethistoricalalarms(id))
    }
    
})
export default connect(mapStateToProps, mapDispatchToProps)(Index)